package com.lgx.mobile.rest.group;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lgx.mobile.entity.Group;
import com.lgx.mobile.service.IGroupService;
import com.lgx.right.service.IUserService;

/**
 * 
 * @author xuyichen
 *
 */
@Controller
@RequestMapping("/getGroup")
public class GetGroupController {
	
	private static final Logger logger = Logger.getLogger(GetGroupController.class);

	@Autowired
	IGroupService groupService;

	public IGroupService getGroupService() {
		return groupService;
	}
	
	@Autowired
	IUserService userService;
	
	public IUserService getUserService() {
		return userService;
	}

	/**
	 * 圈子查询
	 * @param groupId id is key
	 * @return 圈子信息；0：圈子不存在；1：参数异常，有参数为空
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	@ResponseBody
	public Object getGroup(@PathVariable("id") String groupId){
		if(StringUtils.isNotBlank(groupId)){
			Group group = getGroupService().findGroupById(Long.parseLong(groupId));
			if(group != null){
				return group;
			}else{
				if(logger.isDebugEnabled()){
					logger.debug("getGroup faild groupId is error");
				}
//				"getGroup faild please check groupId is exists";
				return "0";
			}
		}else{
			if(logger.isDebugEnabled()){
				logger.debug("getGroup faild groupId is not filled");
			}
//		    "getGroup faild please check groupId is filled";
			return "1";
		}
	}
}
